/**
 * Copyright 2012 Alfredo "Rainbowbreeze" Morresi
 * 
 * This file is part of Eureka! project.
 * 
 * Eureka! is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Eureka! is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with Eureka!. If not, see http://www.gnu.org/licenses/.
 */
package it.rainbowbreeze.eureka.util;

import it.rainbowbreeze.eureka.common.AppEnv;
import it.rainbowbreeze.eureka.common.AppEnv.ObjectsFactory;
import android.content.Context;
import android.test.RenamingDelegatingContext;

/**
 * @author Alfredo "Rainbowbreeze" Morresi
 *
 */
public class TestHelper {
    // ------------------------------------------ Private Fields
    private static Class<? extends ObjectsFactory> mLastObjectFactoryClass = null;
    private static ObjectsFactory defaultObjectsFactory = new ObjectsFactory();  

    // -------------------------------------------- Constructors

    // --------------------------------------- Public Properties


    // ------------------------------------------ Public Methods
    public static boolean init(Context context) {
        return init(context, defaultObjectsFactory);
    }
    
    public static boolean init(
            Context context,
            AppEnv.ObjectsFactory overriddingObjectsFactory) {

        //checks for previous {@link AppEnv.ObjectsFactory} used
        if (null != mLastObjectFactoryClass) {
            if (overriddingObjectsFactory.getClass().equals(mLastObjectFactoryClass))
                return false;
        }

        //initializes the environment
        AppEnv.i(context, overriddingObjectsFactory);
        mLastObjectFactoryClass = overriddingObjectsFactory.getClass();
        
        //custom object initialization
        return true;
    }
    
    /**
     * Creates a mock context where all files have a different name suffix,
     * in order to avoid conflicts with true application files.
     * 
     * @param context
     * @return
     */
    public static Context getMockContext(Context context) {
       return new RenamingDelegatingContext(context, "test.");
    }

    // ----------------------------------------- Private Methods

    // ----------------------------------------- Private Classes
}
